{% extends 'myadmin/index.html' %}

{% block title %}
<title>后台会员列表</title>
{% endblock %}

{% block con %}
<div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
    <div class="widget am-cf">
        <div class="widget-head am-cf">
            <div class="widget-title  am-cf">文章列表</div></div>
        <div class="widget-body  am-fr">
            <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                <div class="am-form-group">
                    <div class="am-btn-toolbar">
                        <div class="am-btn-group am-btn-group-xs">
                            <button type="button" class="am-btn am-btn-default am-btn-success">
                                <span class="am-icon-plus"></span>新增</button>
                            <button type="button" class="am-btn am-btn-default am-btn-secondary">
                                <span class="am-icon-save"></span>保存</button>
                            <button type="button" class="am-btn am-btn-default am-btn-warning">
                                <span class="am-icon-archive"></span>审核</button>
                            <button type="button" class="am-btn am-btn-default am-btn-danger">
                                <span class="am-icon-trash-o"></span>删除</button>
                        </div>
                    </div>
                </div>
            </div>
            <form action="{% url 'user_list' %}">

                <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
                    <div class="am-form-group tpl-table-list-select">
                        <select name='types' data-am-selected="{btnSize: 'sm'}">
                          <option value="all" {% if request.GET.types == 'all' %} selected {% endif %}>全局搜索</option>
                          <option value="nkiname" {% if request.GET.types == 'nkiname' %} selected {% endif %}>名称搜索</option>
                        </select>
                    </div>
                </div>
                <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
                    <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                        <input name="keywords" value="{{ request.GET.keywords }}" type="text" class="am-form-field ">
                        <span class="am-input-group-btn">
                            <button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search"></button>
                          </span>
                    </div>
                </div>
                </form>
            <div class="am-u-sm-12">
                <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black " id="example-r">
                        <tr>
                            <th>ID</th>
                            <th>分类名称</th>
                            <th>父级</th>
                            <th>操作</th></tr>
                        {% for v in data %}
                        <tr class="gradeX" style="line-height: 65px;">
                            <td class="am-text-middle">{{ v.id }}</td>
                            <td class="am-text-middle vname">{{ v.sub }}<span id="ap" uid="{{ v.id }}" vname="{{ v.name }}">{{ v.name }}</span></td>
                            {% if v.pid == '0' %}
                            <td class="am-text-middle">顶级</td>
                            {% else %}
                            <td class="am-text-middle">{{ v.cname }}</td>
                            {% endif %}
                            <td class="am-text-middle">
                                <div class="tpl-table-black-operation">
                                    <a href="javascript:;" uid={{ v.id }} class="tpl-table-black-operation-del delclass">
                                        <i class="am-icon-trash"></i> 删除
                                    </a>
                                </div>
                            </td>
                        </tr>
                        {% endfor %}
                </table>
            </div>
            <div class="am-u-lg-12 am-cf">
                <div class="am-fr">
                    <ul class="am-pagination tpl-pagination">
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    // 执行修改
    $('.vname').dblclick(function(){
        // var text = $(this).attr('vname')
        var a = $(this)
        var span = $(this).find('span')
        var uid = span.attr('uid')
        var text = span.text()
        console.log(a)
        console.log(text)
        var Inp = $('<input type="" style="color:black;" name="" value="'+text+'">')
        span.html(Inp)
        Inp.select()

        Inp.blur(function(){
            var newname = $(this).val()
            if(text==newname){
                span.html(text)
            }else{
                $.get('{% url 'gclass_edit' %}',{'id':uid,'data':newname},function(data){
                    alert(data['msg'])
                    span.html(newname)
                },'json')
            }
        })
    })
    // 执行删除
    $('.delclass').click(function(){
        var uid = $(this).attr('uid')
        var a = $(this)
        $.get('{% url 'gclass_del' %}',{'uid':uid},function(data){
            if(data['code']==0){
                alert(data['msg'])
            }else{
                alert(data['msg'])
                a.parents('tr').remove()
            }
        },'json')
    })
</script>
{% endblock %}